package com.zenithmind.version.pojo.domain;

import com.baomidou.mybatisplus.annotation.TableName;
import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 文件统计信息实体类 - 遵循单一职责原则，专门处理文件统计数据
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("version_file_statistics")
@Schema(description = "文件统计信息实体")
public class FileStatistics extends BaseEntity {

    /**
     * 文件版本ID
     */
    @Schema(description = "文件版本ID")
    private String fileVersionId;

    /**
     * 行数
     */
    @Schema(description = "行数")
    private Integer lineCount;

    /**
     * 新增行数
     */
    @Schema(description = "新增行数")
    private Integer addedLines;

    /**
     * 删除行数
     */
    @Schema(description = "删除行数")
    private Integer deletedLines;

    /**
     * 获取总变更行数
     * 
     * @return 总变更行数
     */
    public int getTotalChangedLines() {
        int added = addedLines != null ? addedLines : 0;
        int deleted = deletedLines != null ? deletedLines : 0;
        return added + deleted;
    }
    
    /**
     * 获取净变更行数（新增 - 删除）
     * 
     * @return 净变更行数
     */
    public int getNetChangedLines() {
        int added = addedLines != null ? addedLines : 0;
        int deleted = deletedLines != null ? deletedLines : 0;
        return added - deleted;
    }
    
    /**
     * 检查是否有变更
     * 
     * @return 是否有变更
     */
    public boolean hasChanges() {
        return getTotalChangedLines() > 0;
    }
    
    /**
     * 检查是否为大型变更
     * 
     * @return 是否为大型变更（变更超过50行）
     */
    public boolean isLargeChange() {
        return getTotalChangedLines() > 50;
    }
    
    /**
     * 获取变更比例
     * 
     * @return 变更比例（0-1之间）
     */
    public double getChangeRatio() {
        if (lineCount == null || lineCount == 0) {
            return 0.0;
        }
        return (double) getTotalChangedLines() / lineCount;
    }
    
    /**
     * 获取新增行比例
     * 
     * @return 新增行比例（0-1之间）
     */
    public double getAddedRatio() {
        if (lineCount == null || lineCount == 0) {
            return 0.0;
        }
        int added = addedLines != null ? addedLines : 0;
        return (double) added / lineCount;
    }
    
    /**
     * 获取删除行比例
     * 
     * @return 删除行比例（0-1之间）
     */
    public double getDeletedRatio() {
        if (lineCount == null || lineCount == 0) {
            return 0.0;
        }
        int deleted = deletedLines != null ? deletedLines : 0;
        return (double) deleted / lineCount;
    }
}
